//
//  ZMVisitorView.swift
//  LoveBeen
//
//  Created by pg on 2017/8/6.
//  Copyright © 2017年 pg. All rights reserved.
//

import UIKit

class ZMVisitorView: UIView {

    //MARK:- 按钮点击事件回调闭包
    var changeAddrButtonClickClosure:(()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.white
        
        setupUI()
    }
    //MARK:- 不支持XIB
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:- 懒加载图片view
    fileprivate lazy var imageView : UIImageView = {
        let view = UIImageView()
        view.image = UIImage(named: "v2_placeholder_full_size")
        
        view.sizeToFit()
        return view
    }()
    
    //MARK:- 懒加载消息提示label
    fileprivate lazy var messageLabel : UILabel = {
       
        let label = UILabel()
        label.text = "抱歉,当前位置暂时没有开通服务,敬请期待哦~"
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor.darkGray
        label.textAlignment = .center
        
        label.sizeToFit()
        return label
    }()
    
    //MARK:- 懒加载按钮
    fileprivate lazy var button: UIButton = {
       
        let btn = UIButton()
        
        btn.setTitle("切换地址", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        btn.setTitleColor(UIColor.orange, for: .normal)
        
        btn.setBackgroundImage(#imageLiteral(resourceName: "white"), for: UIControlState.normal)
        btn.layer.borderWidth = 1
        btn.layer.borderColor = UIColor.orange.cgColor
        btn.adjustsImageWhenHighlighted = false
        
        btn.layer.cornerRadius = 3
        btn.layer.masksToBounds = true
        
        //单击事件
        btn.addTarget(self, action: #selector(buttonClick), for: UIControlEvents.touchUpInside)
        
        return btn
        
        
    }()
    //MARK:- 初始化Ui
    private func setupUI(){
        
        //添加图片
       
        addSubview(imageView)
        imageView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-50)
           // make.width.height.equalTo(80)
       }
        //添加消息提示label
        addSubview(messageLabel)
        messageLabel.snp.makeConstraints { (make) in
            make.top.equalTo(imageView.snp.bottom).offset(10)
            make.centerX.equalTo(self)
        }
       //添加按键
        addSubview(button)
        button.snp.makeConstraints { (make) in
            make.top.equalTo(messageLabel.snp.bottom).offset(10)
            make.centerX.equalTo(self)
            make.width.equalTo(80)
            make.height.equalTo(35)
        }
    }
    
    @objc private func buttonClick(){
        
        changeAddrButtonClickClosure?()
        
    }
    
    
}
